﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using SGSGameServer.Protocal;

namespace SGSGameServer.Protocal
{
    public class SocketHelper
    {
        public static int Send( Socket socket, string data )
        {
            NetMessage msg = new NetMessage( data );
            return socket.Send( msg.ToBytes() );
        }

        public static int Send<T>( Socket socket, T data )
        {
            NetMessage<T> msg = new NetMessage<T>( data );
            return socket.Send( msg.ToBytes() );
        }

        public static NetMessage<T> Receive<T>( Socket socket )
        {
            return NetMessage<T>.FromSocket( socket );
        }
        
    }
}
